let express = require('express')
let router = express.Router()

router.get('/', async (req,res,next) => {
  
  //开库
  let {collection,client,ObjectId} = await req.mgdb.open({collectionName:'user'})

  //兜库，根据token
  collection.find({_id: ObjectId(req.query.decode._id)}).toArray((err,result)=>{
    if(err){
      res.send({err:1,msg:'集合操作失败'})
    }else {
      if(result.length>0){
        delete result[0].username
        delete result[0].password
        res.send({err:0,msg:'自动登录成功',data:result[0]})
      }else{
        res.send({err:1,msg:'自动登录失败'})
      }
    }
    client.close();
  })

})

module.exports=router;